window.addEventListener('load', function () {
  function $ (selector) {
    return document.querySelector(selector)
  }
  $('.container .model').addEventListener('click', function (e) {

    // console.log(e.target);
    var id = e.target.getAttribute('id')
    console.log(id);
    if (e.target.tagName == 'LI') {//点击模块 .获取索引
      console.log(id);
      if (id == 0) {
        console.log(id);
        $('.container').style.backgroundImage = 'url()'//切换背景
        for (var i = 0; i <= 2; i++) {
          $('.modelxia ').children[i].style.display = 'none'//切换模块
        }
        $('.modelxia').children[id].style.display = 'block'
        //选择武器列表
      }
      if (id == 1) {
        $('.container').style.backgroundImage = 'url(./image/模式.jpg)'
        for (var i = 0; i <= 2; i++) {
          $('.modelxia').children[i].style.display = 'none'
        }
        $('.modelxia').children[id].style.display = 'block'

      }
      if (id == 2) {
        $('.container').style.backgroundImage = 'url(./image/地图.jpg)'
        for (var i = 0; i <= 2; i++) {
          $('.modelxia').children[i].style.display = 'none'
        }
        $('.modelxia').children[id].style.display = 'block'
      }
    }
  })
  //武器选择
  for (var i = 0; i < 5; i++) {
    $('.modelxia .wuqi ul').children[i].addEventListener('click', function (e) {
      var index = this.getAttribute('index')
      if (index == 1) {
        $('.contentxx > img').setAttribute("src", "./uploads/手枪1.png")
      } else if (index == 2) {
        $('.contentxx > img').setAttribute("src", "./uploads/AK47.png")
      } else if (index == 3) {
        $('.contentxx > img').setAttribute("src", "./uploads/MP5.png")
      } else if (index == 4) {
        $('.contentxx > img').setAttribute("src", "./uploads/喷子.png")
      } else if (index == 5) {
        $('.contentxx > img').setAttribute("src", "./uploads//匕首.png")
      }
    })
  }
  /*  $('.shortcut em').addEventListener('click', function () {
     $('.guofu').classList.toggle('show1')
   }) */

  function animate (obj, target, callback) {
    // console.log(callback);  callback = function() {}  调用的时候 callback()

    // 先清除以前的定时器，只保留当前的一个定时器执行
    clearInterval(obj.timer)
    obj.timer = setInterval(function () {
      // 步长值写到定时器的里面
      // 把我们步长值改为整数 不要出现小数的问题
      // var step = Math.ceil((target - obj.offsetLeft) / 10);
      var step = (target - window.pageYOffset) / 10
      step = step > 0 ? Math.ceil(step) : Math.floor(step)
      if (window.pageYOffset == target) {
        // 停止动画 本质是停止定时器
        clearInterval(obj.timer)
        // 回调函数写到定时器结束里面
        // if (callback) {
        //     // 调用函数
        //     callback();
        // }
        callback && callback()
      }
      // 把每次加1 这个步长值改为一个慢慢变小的值  步长公式：(目标值 - 现在的位置) / 10
      // obj.style.left = window.pageYOffset + step + 'px';
      window.scroll(0, window.pageYOffset + step)
    }, 15)
  }

  $('.sidenav').addEventListener('click', function (e) {
    var index = e.target.getAttribute('index')//只能获取页面中部分大小.
    console.log(index);
    if (index == 1) {
      var banner = $('.module-news').offsetTop
      console.log(banner);
      animate(window, banner - 112)
    } else
      if (index == 0) {
        animate(window, 0)
      } else
        if (index == 2) {
          var move1 = $('.gamecenter').offsetTop
          console.log(move1);
          animate(window, move1 - 112)
        } else
          if (index == 3) {
            var move2 = $('.container').offsetTop
            console.log(move2);
            animate(window, move2 - 112)
          } else
            if (index == 4) {
              var move3 = $('.tipcenter').offsetTop
              console.log(move3);
              animate(window, move3 - 112)
            }
  })
  /* window.addEventListener('scroll', function () {
    if (window.pageYOffset >= 996) {
      $('.sidenav').style.display = 'block'
    } else { $('.sidenav').style.display = 'none' }
  }) */
  /*   $('.sidenav').children[i].addEventListener('click', function (e) {
      console.log(i);  不能获取li
    }) */
  //三大模块不能点里面
  //不能获取z-index 动态
  //scroll事件绑定在window的
})









